package cn.doitedu.vueapi.dao.tg;


import org.apache.ibatis.annotations.*;
import org.apache.ibatis.jdbc.SQL;
import cn.doitedu.vueapi.pojo.tg.AdResource;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;


@Component
public interface AdResourceMapper{

	@SelectProvider(type = SqlProvider.class, method = "selectByAdResource")
	@ResultMap("BaseResultMap")
	List<AdResource> selectByAdResource(AdResource adResource);

	@InsertProvider(type = SqlProvider.class,method = "insertAdResource")
	int insertAdResource(AdResource adResource);

	@UpdateProvider(type = SqlProvider.class,method = "updateAdResource")
	int updateAdResource(AdResource adResource);

	@DeleteProvider(type = SqlProvider.class,method = "deleteAdResource")
	int deleteAdResource(AdResource adResource);



	 class SqlProvider{
	
		public String selectByAdResource(AdResource adResource){
			SQL sql= new SQL().SELECT("*").FROM("`ad_resource`");
			if(adResource.getId()!=null) sql.AND().WHERE("`id`="+adResource.getId());
			if(adResource.getAdname()!=null) sql.AND().WHERE("`adname`='"+adResource.getAdname()+"'");
			if(adResource.getAdcat()!=null) sql.AND().WHERE("`adcat`='"+adResource.getAdcat()+"'");
			if(adResource.getMbImg()!=null) sql.AND().WHERE("`mb_img`='"+adResource.getMbImg()+"'");
			if(adResource.getMbText()!=null) sql.AND().WHERE("`mb_text`='"+adResource.getMbText()+"'");
			if(adResource.getEwmLeft()!=null) sql.AND().WHERE("`ewm_left`="+adResource.getEwmLeft());
			if(adResource.getEwmTop()!=null) sql.AND().WHERE("`ewm_top`="+adResource.getEwmTop());
			if(adResource.getEwmWidth()!=null) sql.AND().WHERE("`ewm_width`="+adResource.getEwmWidth());
			if(adResource.getEwmHeight()!=null) sql.AND().WHERE("`ewm_height`="+adResource.getEwmHeight());
			if(adResource.getJumpUrl()!=null) sql.AND().WHERE("`jump_url`='"+adResource.getJumpUrl()+"'");
			if(adResource.getCreateTime()!=null) sql.AND().WHERE("`create_time`="+adResource.getCreateTime());
			if(adResource.getUpdateTime()!=null) sql.AND().WHERE("`update_time`="+adResource.getUpdateTime());
			if(adResource.getStatus()!=null) sql.AND().WHERE("`status`='"+adResource.getStatus()+"'");
			if(adResource.getCreateBy()!=null) sql.AND().WHERE("`create_by`='"+adResource.getCreateBy()+"'");
			if(adResource.getUpdateBy()!=null) sql.AND().WHERE("`update_by`='"+adResource.getUpdateBy()+"'");
	
			return sql.toString();
		}
		public String insertAdResource(AdResource adResource){
			SQL sql= new SQL().INSERT_INTO("`ad_resource`");
			if(adResource.getId()!=null) sql.VALUES("`id`",String.valueOf(adResource.getId()));
			if(adResource.getAdname()!=null) sql.VALUES("`adname`","'"+adResource.getAdname()+"'");
			if(adResource.getAdcat()!=null) sql.VALUES("`adcat`","'"+adResource.getAdcat()+"'");
			if(adResource.getMbImg()!=null) sql.VALUES("`mb_img`","'"+adResource.getMbImg()+"'");
			if(adResource.getMbText()!=null) sql.VALUES("`mb_text`","'"+adResource.getMbText()+"'");
			if(adResource.getEwmLeft()!=null) sql.VALUES("`ewm_left`",String.valueOf(adResource.getEwmLeft()));
			if(adResource.getEwmTop()!=null) sql.VALUES("`ewm_top`",String.valueOf(adResource.getEwmTop()));
			if(adResource.getEwmWidth()!=null) sql.VALUES("`ewm_width`",String.valueOf(adResource.getEwmWidth()));
			if(adResource.getEwmHeight()!=null) sql.VALUES("`ewm_height`",String.valueOf(adResource.getEwmHeight()));
			if(adResource.getJumpUrl()!=null) sql.VALUES("`jump_url`","'"+adResource.getJumpUrl()+"'");
			if(adResource.getCreateTime()!=null) sql.VALUES("`create_time`",String.valueOf(adResource.getCreateTime()));
			if(adResource.getUpdateTime()!=null) sql.VALUES("`update_time`",String.valueOf(adResource.getUpdateTime()));
			if(adResource.getStatus()!=null) sql.VALUES("`status`","'"+adResource.getStatus()+"'");
			if(adResource.getCreateBy()!=null) sql.VALUES("`create_by`","'"+adResource.getCreateBy()+"'");
			if(adResource.getUpdateBy()!=null) sql.VALUES("`update_by`","'"+adResource.getUpdateBy()+"'");
			return sql.toString();	
		}
		public String updateAdResource(AdResource adResource){
			SQL sql= new SQL().UPDATE("`ad_resource`");
			if(adResource.getId()!=null) sql.SET("`id`=" + adResource.getId());
			if(adResource.getAdname()!=null) sql.SET("`adname`='" + adResource.getAdname()+"'");
			if(adResource.getAdcat()!=null) sql.SET("`adcat`='" + adResource.getAdcat()+"'");
			if(adResource.getMbImg()!=null) sql.SET("`mb_img`='" + adResource.getMbImg()+"'");
			if(adResource.getMbText()!=null) sql.SET("`mb_text`='" + adResource.getMbText()+"'");
			if(adResource.getEwmLeft()!=null) sql.SET("`ewm_left`=" + adResource.getEwmLeft());
			if(adResource.getEwmTop()!=null) sql.SET("`ewm_top`=" + adResource.getEwmTop());
			if(adResource.getEwmWidth()!=null) sql.SET("`ewm_width`=" + adResource.getEwmWidth());
			if(adResource.getEwmHeight()!=null) sql.SET("`ewm_height`=" + adResource.getEwmHeight());
			if(adResource.getJumpUrl()!=null) sql.SET("`jump_url`='" + adResource.getJumpUrl()+"'");
			if(adResource.getCreateTime()!=null) sql.SET("`create_time`=" + adResource.getCreateTime());
			if(adResource.getUpdateTime()!=null) sql.SET("`update_time`=" + adResource.getUpdateTime());
			if(adResource.getStatus()!=null) sql.SET("`status`='" + adResource.getStatus()+"'");
			if(adResource.getCreateBy()!=null) sql.SET("`create_by`='" + adResource.getCreateBy()+"'");
			if(adResource.getUpdateBy()!=null) sql.SET("`update_by`='" + adResource.getUpdateBy()+"'");
			sql.WHERE("`id`="+adResource.getId());
			return sql.toString();	
		}
		public String deleteAdResource(AdResource adResource){
			SQL sql= new SQL().DELETE_FROM("`ad_resource`");
			if(adResource.getId()!=null) sql.AND().WHERE("`id`=" + adResource.getId());
			if(adResource.getAdname()!=null) sql.AND().WHERE("`adname`='" + adResource.getAdname()+"'");
			if(adResource.getAdcat()!=null) sql.AND().WHERE("`adcat`='" + adResource.getAdcat()+"'");
			if(adResource.getMbImg()!=null) sql.AND().WHERE("`mb_img`='" + adResource.getMbImg()+"'");
			if(adResource.getMbText()!=null) sql.AND().WHERE("`mb_text`='" + adResource.getMbText()+"'");
			if(adResource.getEwmLeft()!=null) sql.AND().WHERE("`ewm_left`=" + adResource.getEwmLeft());
			if(adResource.getEwmTop()!=null) sql.AND().WHERE("`ewm_top`=" + adResource.getEwmTop());
			if(adResource.getEwmWidth()!=null) sql.AND().WHERE("`ewm_width`=" + adResource.getEwmWidth());
			if(adResource.getEwmHeight()!=null) sql.AND().WHERE("`ewm_height`=" + adResource.getEwmHeight());
			if(adResource.getJumpUrl()!=null) sql.AND().WHERE("`jump_url`='" + adResource.getJumpUrl()+"'");
			if(adResource.getCreateTime()!=null) sql.AND().WHERE("`create_time`=" + adResource.getCreateTime());
			if(adResource.getUpdateTime()!=null) sql.AND().WHERE("`update_time`=" + adResource.getUpdateTime());
			if(adResource.getStatus()!=null) sql.AND().WHERE("`status`='" + adResource.getStatus()+"'");
			if(adResource.getCreateBy()!=null) sql.AND().WHERE("`create_by`='" + adResource.getCreateBy()+"'");
			if(adResource.getUpdateBy()!=null) sql.AND().WHERE("`update_by`='" + adResource.getUpdateBy()+"'");
			return sql.toString();	
		}
	}
	
}